package com.hr.牛客网剑指offer;

import java.util.Stack;

/**
 * @author zhz
 * @date 2020/08/23
 **/
public class JZ14_链表中倒数第K个结点 {

    public ListNode FindKthToTail(ListNode head, int k) {
        if (head == null) {
            return null;
        }
        ListNode first = head;
        ListNode last = head;
        for (int i = 0; i < k; i++) {
            if (first == null) {
                return null;
            }
            first = first.next;
        }
        while (first != null && last != null) {
            first = first.next;
            last = last.next;
        }
        return last;
    }
}
